﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace kwzx
{
    public partial class lyb : Form
    {
        public lyb()
        {
            InitializeComponent();
        }

        private void t_BMBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
          
            this.tableAdapterManager.UpdateAll(this.dataSet1);

        }

        private void lyb_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dataSet2.l_k_b”中。您可以根据需要移动或删除它。
            this.l_k_bTableAdapter.Fill(this.dataSet2.l_k_b);
            // TODO: 这行代码将数据加载到表“dataSet1.T_BM”中。您可以根据需要移动或删除它。
       

        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataSet2TableAdapters.正员工发卡表TableAdapter fk = new DataSet2TableAdapters.正员工发卡表TableAdapter();
            DataSet2TableAdapters.l_k_bTableAdapter lkb = new DataSet2TableAdapters.l_k_bTableAdapter();
            DataSet2TableAdapters.临时表TableAdapter lkb2 = new DataSet2TableAdapters.临时表TableAdapter();
            if (textBox1.Text!="")
            {
               
            DataTable tb=    fk.GetDataBy_kh(textBox1.Text.Trim());
            if (tb.Rows.Count < 1)
            {
                MessageBox.Show("无此卡号");
                textBox1.Text = "";
                return;
            }
            else
            {
                string fjh = "";
                for (int i = 0; i < tb.Rows.Count;i++ )
                {
                    if (tb.Rows[0]["name"].ToString().Contains('A') || tb.Rows[0]["name"].ToString().Contains('B'))
                    {
                        if (fjh == "")
                        {
                            fjh += tb.Rows[0]["name"].ToString() + ",";
                        }
                        else
                        {
                            fjh += tb.Rows[0]["name"].ToString() + "";
                        }
                    }
                }
                if (!checkBox1.Checked)
                {
                if (lkb.GetDataBy(textBox1.Text).Rows.Count < 1)
                {
                   
                        lkb.Insert("1", textBox1.Text.Trim(), tb.Rows[0]["xm"].ToString(), tb.Rows[0]["sfzh"].ToString(), tb.Rows[0]["bmmc"].ToString(), int.Parse(tb.Rows[0]["user_id"].ToString()), fjh);
                        this.l_k_bTableAdapter.Fill(this.dataSet2.l_k_b);
                   
                }

                }
                else
                {
                    if (lkb2.GetDataBy(textBox1.Text).Rows.Count < 1)
                    {
                        lkb2.Insert("1", textBox1.Text.Trim(), tb.Rows[0]["xm"].ToString(), tb.Rows[0]["sfzh"].ToString(), tb.Rows[0]["bmmc"].ToString(), int.Parse(tb.Rows[0]["user_id"].ToString()), fjh);
                        //this.l_k_bTableAdapter.Fill(this.dataSet2.临时表);
                    }
                }
                textBox1.Text = "";
            }

            }
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue.ToString() == "13")
            {

                button1_Click(sender, e);
            }
           

            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DataSet2TableAdapters.正员工发卡表TableAdapter fk = new DataSet2TableAdapters.正员工发卡表TableAdapter();
            DataSet2TableAdapters.l_k_bTableAdapter lkb = new DataSet2TableAdapters.l_k_bTableAdapter();
            DataSet2TableAdapters.临时表TableAdapter lkb2 = new DataSet2TableAdapters.临时表TableAdapter();
            if (textBox2.Text != "")
            {

                DataTable tb = fk.GetDataBy_kh(textBox2.Text.Trim());
                if (tb.Rows.Count < 1)
                {
                    MessageBox.Show("无此卡号");
                    textBox2.Text = "";
                    return;
                }
                else
                {
                   string xm= tb.Rows[0]["xm"].ToString();
                   if (textBox3.Text.Contains(xm))
                   {
                     
                       MessageBox.Show("!!!找到人了");
                      
                   }
                        //if (lkb.GetDataBy(textBox1.Text).Rows.Count < 1)
                        //{

                        //   // lkb.Insert("1", textBox1.Text.Trim(), tb.Rows[0]["xm"].ToString(), tb.Rows[0]["sfzh"].ToString(), tb.Rows[0]["bmmc"].ToString(), int.Parse(tb.Rows[0]["user_id"].ToString()), fjh);
                        //    this.l_k_bTableAdapter.Fill(this.dataSet2.l_k_b);

                        //}
                   textBox2.Text = "";
                    
                }

            }
        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue.ToString() == "13")
            {

                button2_Click(sender, e);
            }
        }
    }
}
